package com.dream.springmvc.filter.operators;


import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author panwen
 */
public class Operators {

    public static boolean eqOp(Object v1, Object v2) {
        return Objects.equals(v1, v2);
    }

    public static boolean neOp(Object v1, Object v2) {
        return !Objects.equals(v1, v2);
    }

    public static <T extends Comparable<T>> boolean gtOp(T v1, T v2) {
        return v1.compareTo(v2) > 0;
    }

    public static <T extends Comparable<T>> boolean gteOp(T v1, T v2) {
        return v1.compareTo(v2) >= 0;
    }

    public static <T extends Comparable<T>> boolean ltOp(T v1, T v2) {
        return v1.compareTo(v2) < 0;
    }

    public static <T extends Comparable<T>> boolean lteOp(T v1, T v2) {
        return v1.compareTo(v2) <= 0;
    }

    public static boolean emptyOp(Object v1, Object v2) {
        return ObjectUtils.isEmpty(v2);
    }

    public static boolean notEmptyOp(Object v1, Object v2) {
        return !emptyOp(v1, v2);
    }

    public static boolean stringContainsOp(String v1, String v2) {
        return v2 != null && v2.contains(v1);
    }
    public static boolean stringNotContainsOp(String v1, String v2) {
        return v2 != null && !v2.contains(v1);
    }

    public static <T> boolean listContainsOp(List<T> v1, List<T> v2) {
        // TODO
        return false;
    }

    public static <T> boolean listNotContainsOp(List<T> v1, List<T> v2) {
        // TODO
        return false;
    }

    public static boolean stringEmptyOp(String v1, String v2) {
        return v2 == null || v2.isEmpty();
    }

    public static boolean stringNotEmptyOp(String v1, String v2) {
        return v2 != null && !v2.isEmpty();
    }

    public static <T> boolean listEmptyOp(List<T> v1, List<T> v2) {
        return v2 == null || v2.isEmpty();
    }

    public static <T> boolean stringNotEmptyOp(List<T> v1, List<T> v2) {
        return v2 != null && !v2.isEmpty();
    }

}
